package weaver.interfaces.cese.duss.Test;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.cese.duss.tianyancha.util.HttpClientUtil;
import weaver.common.DateUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;

import java.security.MessageDigest;
import java.util.Random;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-01-20
 * @Description: ${description}
 * @ModifyLog:
 **/

public class test {
    public static void main(String[] args) {
        String currentDate = DateUtil.getCurrentDate();
       int inti =  DateUtil.compDate(currentDate,"2022-11-05");
        System.out.println(inti);


    }

    private static String getItemID(int n) {
        String val = "";
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            String str = random.nextInt( 2 ) % 2 == 0 ? "num" : "char";
            if ("char".equalsIgnoreCase( str )) { // 产生字母
                int nextInt = random.nextInt( 2 ) % 2 == 0 ? 65 : 97;
                val += (char) (nextInt + random.nextInt( 26 ));
            } else if ("num".equalsIgnoreCase( str )) { // 产生数字
                val += String.valueOf( random.nextInt( 10 ) );
            }
        }
        return val;
    }

    //根据Key去重复合并值
    public static JSONArray delRepeatIndexid(JSONArray array, String fykm, String yjje) {
        JSONArray arrayTemp = new JSONArray();
        int num = 0;
        for (int i = 0; i < array.size(); i++) {
            if (num == 0) {
                arrayTemp.add( array.get( i ) );
            } else {
                int numJ = 0;
                for (int j = 0; j < arrayTemp.size(); j++) {
                    JSONObject newJsonObjectI = (JSONObject) array.get( i );
                    JSONObject newJsonObjectJ = (JSONObject) arrayTemp.get( j );
                    String index_idI = newJsonObjectI.get( fykm ).toString();
                    String valueI = newJsonObjectI.get( yjje ).toString();
                    String index_idJ = newJsonObjectJ.get( fykm ).toString();
                    String valueJ = newJsonObjectJ.get( yjje ).toString();
                    if (index_idI.equals( index_idJ )) {
                        double newValue = Util.getDoubleValue( valueI ) + Util.getDoubleValue( valueJ );
                        arrayTemp.remove( j );
                        JSONObject newObject = new JSONObject();
                        newObject.put( fykm, index_idI );
                        newObject.put( yjje, newValue );
                        arrayTemp.add( newObject );
                        break;
                    }
                    numJ++;
                }
                if ((numJ - 1) == (arrayTemp.size() - 1)) {
                    arrayTemp.add( array.get( i ) );
                }
            }
            num++;
        }
        return arrayTemp;
    }

    public static JSONObject getSelectSql(String fields, String table, String sqlwhere, String param) {
        JSONObject resultJson = new JSONObject();
        //RecordSet rs = new RecordSet();
        String sql = "select " + fields + " from " + table + " where " + sqlwhere;
        Object[] params = new Object[]{param};
        String[] arr = fields.split( "," );

        //rs.executeQuery(sql,params);
        //while (rs.next()){
        for (int i = 0; i < arr.length; i++) {
            resultJson.put( arr[i], Util.null2String( arr[i] ) );
        }
        // }
        return resultJson;
    }


    /***
     * MD5加码 生成32位md5码
     */
    public static String string2MD5(String inStr) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance( "MD5" );
        } catch (Exception e) {
            System.out.println( e.toString() );
            e.printStackTrace();
            return "";
        }
        char[] charArray = inStr.toCharArray();
        byte[] byteArray = new byte[charArray.length];

        for (int i = 0; i < charArray.length; i++)
            byteArray[i] = (byte) charArray[i];
        byte[] md5Bytes = md5.digest( byteArray );
        StringBuffer hexValue = new StringBuffer();
        for (int i = 0; i < md5Bytes.length; i++) {
            int val = ((int) md5Bytes[i]) & 0xff;
            if (val < 16)
                hexValue.append( "0" );
            hexValue.append( Integer.toHexString( val ) );
        }
        return hexValue.toString();

    }

    /**
     * 加密解密算法 执行一次加密，两次解密
     */
    public static String convertMD5(String inStr) {

        char[] a = inStr.toCharArray();
        for (int i = 0; i < a.length; i++) {
            a[i] = (char) (a[i] ^ 't');
        }
        String s = new String( a );
        return s;

    }

}
